package top.pengdong.pictureShare.gateway.service.impl;

import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import top.pengdong.pictureShare.common.model.SysConstant;

import javax.annotation.PostConstruct;

/**
 * 用于初始化uir的权限到redis中
 * TODO 实际开发中需要自己维护，此处只是为了演示方便
 * 详情见 cn.myjszl.oauth2.cloud.auth.server.service.impl.LoadRolePermissionService
 */
//@Service
@Deprecated
public class InitService {
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @PostConstruct
    public void init(){
        // 用户登陆注册功能接口
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/oauth/logout", Lists.newArrayList("ROLE_admin","ROLE_user"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/oauth/test", Lists.newArrayList("ROLE_admin","ROLE_user"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/oauth/authorize", Lists.newArrayList("ROLE_admin","ROLE_user"));


        // 管理员用户信息
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/user/add", Lists.newArrayList("ROLE_admin"));


        // 用户操作信息
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/user/delete", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/user/create", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/user/activation", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/user/update", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/user/share", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/user/like", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/user/collection", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/user/view", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/user/tweet", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/user/user_info/*", Lists.newArrayList("ROLE_user", "ROLE_admin"));

        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/user/relation", Lists.newArrayList("ROLE_user", "ROLE_admin"));


        // 用户对于文章的操作
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/user_like", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/delete_user_like", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/user_action_status", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/user_collection", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/delete_user_collection", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/user_collection_status", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/share_tweet", Lists.newArrayList("ROLE_user", "ROLE_admin"));

        // 用户查看操作
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/type", Lists.newArrayList("ROLE_user", "ROLE_admin"));

        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/info/**", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/share", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/search", Lists.newArrayList("ROLE_user", "ROLE_admin"));

        // 管理员 操作 可以删除的
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/add", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/delete", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/update", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/tweet/list", Lists.newArrayList("ROLE_user", "ROLE_admin"));


        // 文件上传操作权限
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/file/upload.json", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/file/get/*", Lists.newArrayList("ROLE_user", "ROLE_admin"));


        // 用户评论操作
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/comment/comment_add", Lists.newArrayList("ROLE_user", "ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/comment/comment_action", Lists.newArrayList("ROLE_user", "ROLE_admin"));

        // 管理员操作
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/api/**", Lists.newArrayList("ROLE_admin"));
    }

}
